package com.framework.seedkit.ui.uiframe.vpagerSlip;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import com.framework.seedkit.R;
import com.framework.seedkit.base.BaseActivity;
import com.framework.seedkit.customwidget.gridview.CusGridView;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by ekimatsu on 16/12/21.
 */

public class NineGridViewAct extends BaseActivity {
    //定义图标数组
    private int[] imageRes = {
            R.mipmap.cardmanager_icon_repayment_gou,
            R.mipmap.cardmanager_icon_repayment_logo,
            R.mipmap.cardmanager_icon_repayment_gou,
            R.mipmap.cardmanager_icon_repayment_logo,
            R.mipmap.cardmanager_icon_repayment_gou,
            R.mipmap.cardmanager_icon_repayment_logo,
            R.mipmap.cardmanager_icon_repayment_gou,
            R.mipmap.cardmanager_icon_repayment_logo,
            R.mipmap.cardmanager_icon_repayment_gou};

    //定义图标下方的名称数组
    private String[] name = {
            "O2O收款",
            "订单查询",
            "转账",
            "手机充值",
            "信用卡还款",
            "水电煤",
            "违章代缴",
            "快递查询",
            "更多"
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        CusGridView gridview = (CusGridView) findViewById(R.id.cus_nine_grid_view);
        int length = imageRes.length;

        //生成动态数组，并且转入数据
        ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
        for (int i = 0; i < length; i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("ItemImage", imageRes[i]);//添加图像资源的ID
            map.put("ItemText", name[i]);//按序号做ItemText
            lstImageItem.add(map);
        }
        //生成适配器的ImageItem 与动态数组的元素相对应
        SimpleAdapter saImageItems = new SimpleAdapter(this,
                lstImageItem,//数据来源
                R.layout.item_cus_graid_layout,//item的XML实现

                //动态数组与ImageItem对应的子项
                new String[]{"ItemImage", "ItemText"},

                //ImageItem的XML文件里面的一个ImageView,两个TextView ID
                new int[]{R.id.iv_item, R.id.tv_item});
        //添加并且显示
        gridview.setAdapter(saImageItems);
        //添加消息处理
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(NineGridViewAct.this,name[position], Toast.LENGTH_LONG).show();
            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.act_nine_grid_layout;
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    public void initView() {
    }

    @Override
    public void initData() {
    }
}
